package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.parkcar.R;

import java.util.ArrayList;
import java.util.List;

import Modle.HistoryBean;
import util.BaseTools;

/**
 * Created by Administrator on 2016/3/8.
 */
public class HistoryAdapter extends BaseAdapter{
    private Context mContext;
    private List<HistoryBean> mList = new ArrayList<>();
    public HistoryAdapter(Context context){
        this.mContext = context;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            holder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.adapter_history,null);
            holder.his_address = (TextView) view.findViewById(R.id.his_address);
            holder.his_time = (TextView) view.findViewById(R.id.his_time);
            holder.his_money = (TextView) view.findViewById(R.id.his_money);
            holder.count_time = (TextView) view.findViewById(R.id.count_time);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
        HistoryBean bean = mList.get(i);
        holder.his_time.setText(BaseTools.getTime(bean.getStart_at(),bean.getEnd_at()));
        if(bean.getIs_pay()==0){
            holder.his_money.setText("待支付");
        }else{
            holder.his_money.setText("已付款");
        }
        holder.his_address.setText(bean.getCar_park().getName());
        holder.count_time.setText(BaseTools.getCountTime(bean.getStart_at(),bean.getEnd_at()));
        return view;
    }
    class ViewHolder{
        TextView his_time,his_money,his_address,count_time;
    }
    public void setData(List<HistoryBean> mList){
        this.mList = mList;
        notifyDataSetChanged();
    }
    public void addData(List<HistoryBean> mList){
        this.mList.addAll(mList);
        notifyDataSetChanged();
    }
}
